﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YJKCoordinate;

namespace SetPipe.Utiltiy
{
	public class RightAngleCornerCurveMaker : PipeIMakeCornerCurves, PipeICheckAngle
	{
		private RightAngleCornerCurveMaker()
		{
		}

		public static RightAngleCornerCurveMaker GetRightAngleCornerCurveMake()
		{
			if (RightAngleCornerCurveMaker.singleTag == null)
			{
				RightAngleCornerCurveMaker.singleTag = new RightAngleCornerCurveMaker();
			}
			return RightAngleCornerCurveMaker.singleTag;
		}

		public List<Curve> PipeGetCornerBoundryCurves(ThreePipeInputDataPacker input, out XYZ startPoint_Mid, out XYZ endPoint_Mind)
		{
			List<Curve> list = new List<Curve>();
			XYZ xyz;
			XYZ xyz2;
			XYZ xyz3;
			XYZ xyz4;
			if (!Utiltiy.GetCornernRectangle(input, out xyz, out xyz2, out xyz3, out xyz4))
			{
				startPoint_Mid = xyz.Add(xyz3).Divide(2.0);
				endPoint_Mind = xyz.Add(xyz4).Divide(2.0);
			}
			else if (input.GetTwoInputData(0).GetPipeParameters(1)[PipeUseParameterEnum.Width] > input.GetTwoInputData(1).GetPipeParameters(1)[PipeUseParameterEnum.Width])
			{
				startPoint_Mid = xyz2.Add(xyz3).Divide(2.0);
				endPoint_Mind = xyz.Add(xyz4).Divide(2.0);
			}
			else
			{
				if (input.GetTwoInputData(0).GetPipeParameters(1)[PipeUseParameterEnum.Width] >= input.GetTwoInputData(1).GetPipeParameters(1)[PipeUseParameterEnum.Width])
				{
					throw new CornerMakerException(StaticRescource.StrDontWantIf);
				}
				startPoint_Mid = xyz.Add(xyz3).Divide(2.0);
				endPoint_Mind = xyz2.Add(xyz4).Divide(2.0);
			}
			list = Utiltiy.GetLstBoundLineCurve(new List<XYZ>
			{
				xyz,
				xyz3,
				xyz2,
				xyz4
			});
			if (Utiltiy.CheckNoneEndInterintersection(list))
			{
				throw new CornerMakerException(StaticRescource.StrError_cornerLineIntersection);
			}
			return list;
		}

		public bool PipeIfAngleCanUse(ThreePipeInputDataPacker input)
		{
			return true;
		}

		private static RightAngleCornerCurveMaker singleTag;
	}
}
